package com.wudi.estate.mapper.ownermanagement;

import com.wudi.estate.bean.ownermanagement.Pet;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface PetMapper {
    @Select("select * from pet")
    List<Pet> selectAll() throws Exception;
    @Select("select * from pet where id = #{id}")
    Pet selectById(Pet p) throws Exception;

    @Insert("insert into pet values (default,#{img},#{name},#{color},#{remark},#{adoptTime},#{createTime},#{pid},#{state})")
    void insert(Pet p) throws Exception;

    @Update("update pet set state = #{state} where id =#{id}")
    void updateStateById(Pet p) throws Exception;
    @Update("update pet set img=#{img},name=#{name},color=#{color},remark=#{remark},adopt_time=#{adoptTime},create_time=#{createTime},state=#{state},pid=#{pid} where id =#{id}")
    void updateById(Pet p) throws Exception;

    @Select("select * from pet where name like '%${somename}%'")
    List<Pet> selectByName(String somename) throws Exception;

    @Select("SELECT pet.*,personnel.name pname  FROM pet LEFT JOIN personnel ON pet.pid=personnel.id ")
    List<Map<String, Object>> selectAllTwo()throws Exception;
}
